package com.jj.filter;


import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;
//拦截所有请求
//@WebFilter(urlPatterns = "/*")
public class DemoFilter implements Filter {
//    初始化，只调用一次
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("初始化....");
    }
//放行请求,可以调用多次,request表示请求对象，response表示响应对象，chain表示过滤器链，放行请求
    @Override
    public void doFilter(ServletRequest rquest, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("过滤前请求...");
//        放行请求
        chain.doFilter(rquest, response);

        System.out.println("过滤后请求...");
    }
//销毁，只调用一次
    @Override
    public void destroy() {
        System.out.println("销毁....");
    }
}
